home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d20
/
yuck_200.arc
/
YUCK.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-29
|
49KB
|
1,630 lines
#include "yuck.h" /* check this file for release notes */
/* ========================================================================= */
tNod * pts; /* pointer to first element in list */
int maxpt = 0; /* next free point entry */
int lastpolz = -1; /* last include selected by polz() */
Word MAXMAP = 0; /* current allocated "map"s */
YesNo inPointnet = No; /* flag var for parseRec() */
YesNo inFd199b = No; /* flag var for parseRec() */
tCfg Cfg; /* configuration record */
Byte * Cmd[] = { "infile", "oldnet", "nodelist", "unpublished", "zone",
"kill", "map", "tim_net", "fd199b", "include", "prolog",
"epilog", "userlist", "sysname", "sysloc", "maxpts",
"userkill", "userout", "sort", "tempsort", "keeppvt",
"lfonly", "cronly", "crlf", "clist", "infd199b",
"tim_fake", "tim_trim" };
#define MAXCMD ( sizeof( Cmd ) / sizeof( Cmd[0] ) )
/* ========================================================================= */
/* Cmnt != 0 strips comments at EOL and trims spaces */
Byte * getLine( Byte * p, FILE * fp, int Cmnt )
{
Byte * q;
Loop: if ( fgets( p, 255, fp ) == NULL ) return NULL;
assert( p, 255 );
q = p; skip( q );
if ( *q == '\n' || *q == ';' || *q == EOS )
goto Loop;
q = strchr( p, '\n' );
if ( q != NULL ) *q = EOS;
if ( Cmnt == 0 ) return p;
q = strchr( p, ';' );
if ( q != NULL ) *q = EOS;
q = p + strlen( p ) - 1;
while ( q >= p && ( *q == ' ' || *q == '\t' ) )
q --;
*( q + 1 ) = EOS;
if ( *p == EOS ) /* nothing left? */
goto Loop; /* get another line */
return p;
}
/* ========================================================================= */
void parseAd( Byte * p, tAd * a )
{
Byte * s, * t, * oldp;
memset( a, EOS, sizeof( tAd ) );
skip( p );
oldp = p;
s = p + strlen( p ) - 1;
while ( s >= p && ( *s == ' ' || *s == '\t' ) ) s --;
s[1] = EOS;
s = strchr( p, ':' );
if ( s == NULL ) a->z = 0;
else {
a->z = (Word) strtol( p, &t, 10 );
if ( t != s ) {
printf( "parseAd: bad zone# '%s'\n", oldp );
exit( 1 );
}
p = t + 1; /* point past ':' */
}
s = strchr( p, '/' );
if ( s == NULL ) a->n = 0;
else {
a->n = (Word) strtol( p, &t, 10 );
if ( t != s ) {
printf( "parseAd: bad net# '%s'\n", oldp );
exit( 1 );
}
p = t + 1; /* point past '/' */
}
a->f = (Word) strtol( p, &t, 10 );
if ( *t == EOS ) return;
if ( *t != '.' ) {
printf( "parseAd: junk after node# '%s'\n", oldp );
exit( 1 );
}
t ++;
a->p = (Word) strtol( t, &s, 10 );
if ( *s != EOS ) {
printf( "parseAd: junk after point# '%s'\n", oldp );
exit( 1 );
}
}
/* ========================================================================= */
void makeName( Byte * p )
{
Byte * q, * s;
int maxno, r;
static Byte t[80], maxnam[14];
#if defined( AMIGA )
struct FILEINFO * fb;
if ( ( fb = malloc( sizeof( struct FILEINFO ) ) ) == NULL ) {
puts( "Out of memory on FILEINFO alloc" );
exit( 1 );
}
#else /* AMIGA */
static struct find_t fb;
#endif /* AMIGA */
q = strrchr( p, '/' );
if ( q == NULL ) q = p;
q = strchr( q, '.' );
if ( q != NULL ) return; /* extension present, don't mess up */
strcpy( t, p );
strcat( t, WILDCARD );
maxno = -1; /* none found */
#if defined( AMIGA )
r = dfind( fb, t, 0 );
#else /* AMIGA */
r = _dos_findfirst( t, _A_NORMAL | _A_RDONLY |
_A_HIDDEN | _A_SYSTEM | _A_ARCH, &fb );
#endif /* AMIGA */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
while ( r == 0 ) {
q = strrchr( FFNAME, '.' );
if ( q != NULL && strlen( ++ q ) == 3 ) {
r = (int) strtol( q, &s, 10 );
if ( s == q + 3 && *s == EOS ) {
if ( r > maxno ) {
maxno = r;
strcpy( maxnam, FFNAME );
}
}
}
#if defined( AMIGA )
r = dnext( fb );
#else /* AMIGA */
r = _dos_findnext( &fb );
#endif /* AMIGA */
}
if ( maxno == -1 ) {
printf( "makeName: no file qualified '%s'\n", t );
exit( 1 );
}
q = strrchr( maxnam, '.' );
strcat( p, q );
}
/* ========================================================================= */
void makeDir( Byte * p )
{
strlwr( p );
for ( ; *p; p ++ )
if ( *p == '\\' ) *p = '/';
}
/* ========================================================================= */
void readCfg( Byte * cfgName )
{
FILE * fp;
Byte * s, * t, * p;
#if defined( BIGBUF )
char * filbuf;
#endif
int i;
static Byte Buf[256], Temp[256];
memset( &Cfg, EOS, sizeof( Cfg ) );
Cfg.trimJunk = Cfg.putUnpub = Yes;
Cfg.maxtim = Cfg.maxmap = MAXMAP = 0; /* no mappings yet */
strcpy( Cfg.iFile, "pointnet" );
strcpy( Cfg.oFile, "fdptnet" );
strcpy( Cfg.nFile, "nodelist" );
strcpy( Cfg.tFile, SORTTEMP );
strcpy( Cfg.sysName, POINTNAME );
strcpy( Cfg.sysLoc, POINTLOC );
strcpy( Cfg.sysFlags, POINTFLAGS );
strcpy( Cfg.Sort, SORTCMD );
strcpy( Cfg.termOldnet, CRLF );
strcpy( Cfg.termFd199b, CRLF );
strcpy( Cfg.termClist, CRLF );
strcpy( Cfg.termUser, CRLF );
strcpy( Buf, cfgName );
fp = fopen( cfgName, O_RT );
#if defined( AMIGA )
if ( fp == NULL ) {
strcpy( Buf, MAILDIR );
strcat( Buf, cfgName );
fp = fopen( Buf, O_RT );
}
#endif /* AMIGA */
if ( fp == NULL ) { /* this sucks! */
printf( "readCfg: cfg open failed '%s'\n", Buf );
exit( 1 );
}
#if defined( BIGBUF )
filbuf = malloc( FBUFSIZ );
if ( filbuf == NULL )
printf( "WARNING: no core for file buffer in readCfg()\n" );
else setvbuf( fp, filbuf, _IOFBF, FBUFSIZ );
#endif
while ( getLine( Buf, fp, 1 ) == Buf ) {
s = Buf;
skip( s );
for ( t = Temp; *s && *s != ' ' && *s != '\t'; s ++, t ++ )
*t = *s;
*t = EOS;
skip( s );
t = s;
nskip( t );
for ( i = 0; i < MAXCMD; i ++ )
if ( stricmp( Cmd[i], Temp ) == 0 )
goto Found;
printf( "readCfg: I/O error '%s'\n", Temp );
exit( 1 );
Found: switch ( i ) { /* cmd */
/* infile */
case 0: if ( strnicmp( s, "-k", 2 ) == 0 ) {
Cfg.killInput = Yes;
s = t; skip( s );
t = s; nskip( t );
}
if ( *t ) {
printf( "readCfg: junk 1 at EOL '%s'\n", t );
exit ( 1 );
}
strcpy( Cfg.iFile, s );
Cfg.havePointnet = Yes;
break;
/* oldnet */
case 1: Cfg.Oldnet = Yes;
if ( strnicmp( s, "-a", 2 ) == 0 ) {
Cfg.doInclude = Yes;
s = t; skip( s );
t = s; nskip( t );
}
if ( *t ) {
printf( "readCfg: junk 2 at EOL '%s'\n", t );
exit ( 1 );
}
strcpy( Cfg.oFile, s );
break;
/* nodelist */
case 2: if ( *t ) {
printf( "readCfg: junk 3 at EOL '%s'\n", t );
exit ( 1 );
}
strcpy( Cfg.nFile, s );
break;
/* unpublished */
case 3: if ( *t ) {
printf( "readCfg: junk 3a at EOL '%s'\n", t );
exit ( 1 );
}
if ( stricmp( s, "yes" ) == 0 )
Cfg.putUnpub = Yes;
else if ( stricmp( s, "no" ) == 0 )
Cfg.putUnpub = No;
else {
puts( "readCfg: 'unpublished' requires 'yes' or 'no'." );
exit( 1 );
}
break;
/* zone */
case 4: Cfg.myZone = (Word) strtol( s, &t, 10 );
if ( t == s || *t != EOS ) {
printf( "readCfg: no valid zone# '%s'\n", s );
exit( 1 );
}
break;
/* kill */
case 5: if ( Cfg.maxkill == MAXKILL ) {
printf( "readCfg: too many 'kill' nets (max is %u)\n",
MAXKILL );
exit( 1 );
}
Cfg.killNet[Cfg.maxkill ++] = (Word) strtol( s, &t, 10 );
if ( t == s || *t != EOS ) {
printf( "readCfg: no valid killnet# '%s'\n", s );
exit( 1 );
}
break;
/* map */
case 6: if ( Cfg.maxmap == MAXMAP ) {
MAXMAP += MAPINC; /* increase current */
if ( MAXMAP == MAPINC ) { /* none alloc'ed? */
Cfg.mapNet = malloc( (Word) MAXMAP *
(Word) sizeof( Word ) );
Cfg.mapAd = malloc( (Word) MAXMAP *
(Word) sizeof( tAd ) );
}
else { /* must enlarge? */
Cfg.mapNet = realloc( Cfg.mapNet,
(Word) MAXMAP * (Word) sizeof( Word ) );
Cfg.mapAd = realloc( Cfg.mapAd,
(Word) MAXMAP * (Word) sizeof( tAd ) );
}
if ( Cfg.mapNet == NULL || Cfg.mapAd == NULL ) {
printf( "readCfg: too many 'map' nets (tried %u)\n",
MAXMAP );
exit( 1 );
}
}
Cfg.mapNet[Cfg.maxmap] = (Word) strtol( s, &t, 10 );
if ( t == s || ( *t != ' ' && *t != '\t' ) ) {
printf( "readCfg: no valid mapnet# or EOL '%s'\n", s );
exit( 1 );
}
skip( t );
s = t; nskip( s );
if ( *s ) {
printf( "readCfg: junk 4 at EOL '%s'\n", t );
exit ( 1 );
}
parseAd( t, &Cfg.mapAd[Cfg.maxmap] );
if ( Cfg.mapAd[Cfg.maxmap].p != 0 ) {
printf( "readCfg: no map point# allowed '%s'\n",
Buf );
exit( 1 );
}
Cfg.maxmap ++;
break;
/* tim_net */
case 7: Cfg.fakenet = (Word) strtol( s, &t, 10 );
if ( t == s || *t != EOS ) {
printf( "readCfg: no valid fakenet# '%s'\n", s );
exit( 1 );
}
puts( "WARNING: operating in tim_net mode!" );
Cfg.N109 = Yes;
break;
/* fd199b */
case 8: Cfg.Fd199b = Yes;
if ( *t ) {
printf( "readCfg: junk 5 at EOL '%s'\n", t );
exit ( 1 );
}
strcpy( Cfg.fFile, s );
break;
/* include */
case 9: if ( Cfg.maxinc == MAXINC ) {
printf( "readCfg: max includes is %u.\n",
MAXINC );
exit( 1 );
}
if ( *s == EOS ) {
printf( "readCfg: missing parameter '%s'\n",
Buf );
exit( 1 );
}
Cfg.incNet[Cfg.maxinc].incHdr = No;
if ( strnicmp( s, "-h", 2 ) == 0 ) {
Cfg.incNet[Cfg.maxinc].incHdr = Yes;
s = t; skip( s );
t = s; nskip( t );
}
t = s; nskip( t ); /* point to first whitespace */
if ( *t == EOS ) {
printf( "readCfg: missing region # '%s'\n", Buf );
exit( 1 );
}
*( t ++ ) = EOS;
if ( stricmp( s, "region" ) == 0 )
Cfg.incNet[Cfg.maxinc].Type = Region;
else if ( stricmp( s, "zone" ) == 0 )
Cfg.incNet[Cfg.maxinc].Type = Zone;
else if ( stricmp( s, "net" ) == 0 )
Cfg.incNet[Cfg.maxinc].Type = Host;
else {
printf( "readCfg: invalid include '%s'\n", s );
exit( 1 );
}
s = t; skip( s );
Cfg.incNet[Cfg.maxinc].a.z =
(Word) strtol( s, &t, 10 );
if ( Cfg.incNet[Cfg.maxinc].Type == Region ||
Cfg.incNet[Cfg.maxinc].Type == Host ) {
if ( *t != ':' ) {
printf( "readCfg: no valid region# '%s'\n", s );
exit( 1 );
}
t ++;
Cfg.incNet[Cfg.maxinc].a.n =
(Word) strtol( t, &s, 10 );
p = s; s = t; t = p;
}
if ( t == s || *t != EOS ) {
printf( "readCfg: no valid include# '%s'\n", s );
exit( 1 );
}
Cfg.maxinc ++;
break;
/* prolog */
case 10: Cfg.haveProlog = Yes;
if ( *t ) {
printf( "readCfg: junk 8 at EOL '%s'\n", t );
exit ( 1 );
}
strcpy( Cfg.pFile, s );
break;
/* epilog */
case 11: Cfg.haveEpilog = Yes;
if ( *t ) {
printf( "readCfg: junk 9 at EOL '%s'\n", t );
exit ( 1 );
}
strcpy( Cfg.eFile, s );
break;
/* userlist */
case 12: if ( strnicmp( s, "-k", 2 ) == 0 ) {
Cfg.killUserlist = Yes;
s = t; skip( s );
t = s; nskip( t );
}
if ( *t ) {
printf( "readCfg: junk 91 at EOL '%s'\n", t );
exit ( 1 );
}
strcpy( Cfg.uFile, s );
Cfg.haveUserlist = Yes;
break;
/* sysname */
case 13: strncpy( Cfg.sysName, s, 36 );
Cfg.sysName[36] = EOS;
break;
/* sysloc */
case 14: strncpy( Cfg.sysLoc, s, 36 );
Cfg.sysLoc[36] = EOS;
break;
/* maxpts */
case 15: puts( "** the \"maxpts\" command is obsolete in this and future versions." );
puts( "** it will, for the time being, be accepted (but ignored) for" );
puts( "** compatibility reasons. please remove the \"maxpts\" command from" );
puts( "** your Yuck! control files." );
break;
/* userkill */
case 16: if ( Cfg.maxukill == MAXUKILL ) {
printf( "readCfg: too many 'userkill' entries (max is %u)\n",
MAXUKILL );
exit( 1 );
}
parseAd( s, &Cfg.killUser[Cfg.maxukill] );
#if defined( BREAK_MSC ) /* DO NOT ENABLE -- OPTIMIZER DIES! */
if ( Cfg.killUser[Cfg.maxukill].p != 0 ) {
printf( "readCfg: no userkill point# allowed '%s'\n",
Buf );
exit( 1 );
}
#endif /* DO NOT ENABLE -- OPTIMIZER DIES! */
Cfg.maxukill ++;
break;
/* userout */
case 17: Cfg.haveUserout = Yes;
if ( strnicmp( s, "-a", 2 ) == 0 ) {
Cfg.uoInclude = Yes;
s = t; skip( s );
t = s; nskip( t );
}
if ( *t ) {
printf( "readCfg: junk 22 at EOL '%s'\n", t );
exit ( 1 );
}
strcpy( Cfg.lFile, s );
break;
/* sort */
case 18: strcpy( Cfg.Sort, s );
break;
/* tempsort */
case 19: if ( *t ) {
printf( "readCfg: junk 25 at EOL '%s'\n", t );
exit ( 1 );
}
strcpy( Cfg.tFile, s );
break;
/* keeppvt */
case 20: if ( *t ) {
printf( "readCfg: junk 23 at EOL '%s'\n", t );
exit ( 1 );
}
if ( stricmp( s, "yes" ) == 0 )
Cfg.keepPvt = Yes;
else if ( stricmp( s, "no" ) == 0 )
Cfg.keepPvt = No;
else {
puts( "readCfg: 'keeppvt' requires 'yes' or 'no'." );
exit( 1 );
}
break;
/* lfonly */
case 21:
/* cronly */
case 22:
/* crlf */
case 23: if ( *t ) {
printf( "readCfg: junk 39 at EOL '%s'\n", t );
exit ( 1 );
}
if ( stricmp( s, "oldnet" ) == 0 )
p = Cfg.termOldnet;
else if ( stricmp( s, "fd199b" ) == 0 )
p = Cfg.termFd199b;
else if ( stricmp( s, "userout" ) == 0 )
p = Cfg.termUser;
else if ( stricmp( s, "clist" ) == 0 )
p = Cfg.termClist;
else {
printf( "%s is not a valid parameter to %s.\n",
s, Temp );
exit( 1 );
}
strcpy( p, i == 21? LF: ( i == 22? CR: CRLF ) );
break;
/* clist */
case 24: Cfg.Clist = Yes;
if ( *t ) {
printf( "readCfg: junk 5 at EOL '%s'\n", t );
exit ( 1 );
}
strcpy( Cfg.cFile, s );
break;
/* infd199b */
case 25: if ( strnicmp( s, "-k", 2 ) == 0 ) {
Cfg.killInfd199b = Yes;
s = t; skip( s );
t = s; nskip( t );
}
if ( *t ) {
printf( "readCfg: junk 81 at EOL '%s'\n", t );
exit ( 1 );
}
strcpy( Cfg.bFile, s );
Cfg.haveInfd199b = Yes;
break;
/* tim_fake */
case 26: if ( Cfg.maxtim == MAXTIM ) {
printf( "readCfg: too many 'tim_fake' nets (max is %u)\n",
MAXTIM );
exit( 1 );
}
Cfg.timfake[Cfg.maxtim ++] = (Word) strtol( s, &t, 10 );
if ( t == s || *t != EOS ) {
printf( "readCfg: no valid tim_fake# '%s'\n", s );
exit( 1 );
}
break;
/* tim_trim */
case 27: if ( *t ) {
printf( "readCfg: junk 27a at EOL '%s'\n", t );
exit ( 1 );
}
if ( stricmp( s, "yes" ) == 0 )
Cfg.trimJunk = Yes;
else if ( stricmp( s, "no" ) == 0 )
Cfg.trimJunk = No;
else {
puts( "readCfg: 'tim_trim' requires 'yes' or 'no'." );
exit( 1 );
}
break;
default: printf( "readCfg: switch fucked up %04xh\n", i );
exit( 1 );
} /* cmd */
}
/* ------------------------------------------------------------------------- */
fclose( fp );
#if defined( BIGBUF )
if ( filbuf != NULL )
free( filbuf );
filbuf = NULL;
#endif
for ( s = Cfg.sysName; *s; s ++ )
if ( *s == ' ' || *s == '\t' )
*s = '_';
for ( s = Cfg.sysLoc; *s; s ++ )
if ( *s == ' ' || *s == '\t' )
*s = '_';
if ( *Cfg.sysName != EOS ) /* do not use sysop name as system name? */
Cfg.haveSysname = Yes;
/* ------------------------------------------------------------------------- */
makeDir( Cfg.iFile );
makeDir( Cfg.bFile );
makeDir( Cfg.uFile );
makeDir( Cfg.oFile );
makeDir( Cfg.fFile );
makeDir( Cfg.cFile );
makeDir( Cfg.lFile );
makeDir( Cfg.nFile );
makeDir( Cfg.pFile );
makeDir( Cfg.eFile );
makeDir( Cfg.tFile );
makeName( Cfg.nFile );
if ( Cfg.havePointnet == Yes )
makeName( Cfg.iFile );
if ( Cfg.haveInfd199b == Yes )
makeName( Cfg.bFile );
if ( Cfg.haveUserlist == Yes )
makeName( Cfg.uFile );
if ( Cfg.havePointnet )
p = Cfg.iFile;
else if ( Cfg.haveInfd199b )
p = Cfg.bFile;
else if ( Cfg.haveUserlist )
p = Cfg.uFile;
else {
puts( "Wozzat? no input file? ABORTED!" );
exit( 1 );
}
s = strrchr( Cfg.tFile, '/' );
if ( s == NULL ) s = Cfg.tFile;
t = strchr( s, '.' );
if ( t == NULL ) strcat( Cfg.tFile, strrchr( p, '.' ) );
s = strrchr( Cfg.oFile, '/' );
if ( s == NULL ) s = Cfg.oFile;
t = strchr( s, '.' );
s = strrchr( Cfg.lFile, '/' );
if ( s == NULL ) s = Cfg.lFile;
t = strchr( s, '.' );
if ( t == NULL ) strcat( Cfg.lFile, strrchr( p, '.' ) );
s = strrchr( Cfg.fFile, '/' );
if ( s == NULL ) s = Cfg.fFile;
t = strchr( s, '.' );
if ( t == NULL ) strcat( Cfg.fFile, strrchr( p, '.' ) );
s = strrchr( Cfg.cFile, '/' );
if ( s == NULL ) s = Cfg.cFile;
t = strchr( s, '.' );
if ( t == NULL ) strcat( Cfg.cFile, strrchr( p, '.' ) );
}
/* ========================================================================= */
void dumpRec( tNod * b, FILE * o, int nl )
{
Byte * p;
static Byte Temp[50], oBuf[256];
p = &oBuf[0];
sprintf( Temp, "%u:%u", b->a.z, b->a.n );
p = oBuf + sprintf( oBuf, "\r%-6.6s %9s/", aTyp[(int) b->Type], Temp );
sprintf( Temp, "%u.%u", b->a.f, b->a.p );
sprintf( p, "%-10s %5u %-40.40s %-40.40s %-40.40s %-40.40s %5u %-40.40s",
Temp, b->No, b->Bbs, b->City, b->Sysop, b->Tel, b->Baud, b->Flags );
assert( oBuf, 255 );
if ( o == NULL ) {
oBuf[79] = EOS;
if ( nl ) puts( oBuf );
else fputs( oBuf, stdout );
}
else {
fputs( oBuf, o );
if ( nl ) putc( '\n', o );
}
}
/* ========================================================================= */
int find( Word ln, Word * p, int n )
{
Word * q = p;
for ( ; n; n --, p ++ )
if ( ln == *p ) return p - q;
return -1;
}
/* ========================================================================= */
void killNets( void )
{
tNod * p;
Word ln;
int state;
tAd null;
null.z = null.n = null.f = null.p = 0;
state = 0; ln = 0xffff;
for ( p = pts; p != NULL; p = p->nx ) {
switch ( state ) {
case 0: if ( ln == p->a.n )
break;
ln = p->a.n;
if ( find( ln, Cfg.killNet, Cfg.maxkill ) != -1 ) {
state = 1; /* set state to "kill" */
p->a = null;
}
break;
case 1: if ( ln == p->a.n ) {
p->a = null;
break;
}
ln = p->a.n;
if ( find( ln, Cfg.killNet, Cfg.maxkill ) == -1 ) {
state = 0; /* set state to "nokill" */
}
break;
default: printf( "killNets: illegal state %04xh\n", state );
exit( 1 );
}
}
}
/* ========================================================================= */
int get109( Byte * str, Word * net, Word * nod ) /* parse Jasionowski */
{
Byte * s, * t;
Word temp;
Byte tStr[20];
s = strrchr( str, N109FCHR );
if ( s == NULL ) goto noNet;
sprintf( tStr, "%c%%u%c%%u", N109FCHR, N109CHR );
if ( 2 != sscanf( s, tStr, net, nod ) ) goto noNet;
if ( Cfg.trimJunk == Yes ) *s = EOS;
return 1;
noNet: s = strrchr( str, N109CHR );
if ( s == NULL )
return 0;
s ++;
temp = (Word) strtol( s, &t, 10 );
if ( *t == EOS && t > s ) {
*net = Cfg.fakenet, *nod = temp; /* valid boss# */
if ( Cfg.trimJunk == Yes ) *( s - 1 ) = EOS;
return 1;
}
return 0;
}
/* ========================================================================= */
void mapNets( void )
{
Word ln, temp;
int findres;
tAd la;
tNod * p;
ln = 0xffff;
for ( p = pts; p != NULL; p = p->nx ) {
doit: if ( p->a.n == ln ) {
temp = p->a.f;
p->a = la;
p->a.p = temp;
p->Type = Point;
if ( Cfg.N109 == Yes ) {
Word tnet, tnod;
tnet = tnod = 0;
if ( 0 == get109( p->Bbs, &tnet, &tnod ) )
continue;
if ( tnet != 0 )
p->a.n = tnet;
p->a.f = tnod;
}
continue;
}
ln = p->a.n;
findres = find( ln, Cfg.mapNet, Cfg.maxmap );
if ( findres == -1 && ln != 0 ) {
findres = find( ln, Cfg.timfake, Cfg.maxtim );
if ( findres == -1 && ln != 0 ) {
printf( "Killing unmapped net %u\n", ln );
la.z = la.n = la.f = la.p = 0;
}
}
else la = Cfg.mapAd[findres];
goto doit;
}
}
/* ========================================================================= */
void removeNets( void )
{
tNod * p;
tNod * q;
p = pts;
while ( p != NULL ) {
if ( p->a.n == 0 ) {
q = p;
p = p->nx;
delNod( q );
maxpt --;
}
else p = p->nx;
}
}
/* ========================================================================= */
void dumpList( void )
{
tNod * p;
for ( p = pts; p != NULL; p = p->nx )
dumpRec( p, NULL, 1 );
putchar( '\n' );
}
/* ========================================================================= */
int needed( tAd a )
{
tNod * p;
for ( p = pts; p != NULL; p = p->nx ) {
if ( p->a.z == a.z && p->a.n == a.n && p->a.f == a.f )
return 1;
}
return 0;
}
/* ========================================================================= */
void wrtRec( tNod * p, FILE * of, YesNo Fd199b, Byte * Term )
{
Word n;
Byte * typeStr;
typeStr = aTyp[(int) p->Type];
switch ( p->Type ) {
case Zone: n = p->a.z; fprintf( of, ";%s", Term ); break;
case Region:
case Host: n = p->a.n; fprintf( of, ";%s", Term ); break;
case Point: n = p->a.p;
if ( Cfg.putUnpub == Yes )
strcpy( p->Tel, "-Unpublished-" );
if ( Fd199b == Yes )
typeStr = "";
break;
default: n = p->a.f; break;
}
fprintf( of, "%s,%u,%s,%s,%s,%s,%u,%s%s", typeStr, n,
p->Bbs, p->City, p->Sysop, p->Tel, p->Baud, p->Flags, Term );
/* *** dumpRec( p, NULL, 1 ); */
}
/* ========================================================================= */
/* Type == Point is a special case: a contains a Zone entry's address. polz */
/* should return 1 if any regions from that zone are to be included. this is */
/* used to determine whether a Zone entry should be written without the copy */
/* mode being set to 1 (copy entire zone). */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
int polz( eTyp Type, tAd a )
{
int i;
if ( Type == Point ) {
for ( i = 0; i < Cfg.maxinc; i ++ )
if ( ( Region == Cfg.incNet[i].Type ||
Host == Cfg.incNet[i].Type ) &&
a.z == Cfg.incNet[i].a.z ) {
lastpolz = i;
return 1;
}
return 0;
}
else if ( Type == Host ) {
for ( i = 0; i < Cfg.maxinc; i ++ )
if ( Type == Cfg.incNet[i].Type &&
a.n == Cfg.incNet[i].a.n && a.z == Cfg.incNet[i].a.z ) {
lastpolz = i;
return 1;
}
return 0;
}
else if ( Type == Region ) {
for ( i = 0; i < Cfg.maxinc; i ++ )
if ( Type == Cfg.incNet[i].Type &&
a.n == Cfg.incNet[i].a.n && a.z == Cfg.incNet[i].a.z ) {
lastpolz = i;
return 1;
}
return 0;
}
else if ( Type == Zone ) {
for ( i = 0; i < Cfg.maxinc; i ++ )
if ( Type == Cfg.incNet[i].Type &&
a.z == Cfg.incNet[i].a.z ) {
lastpolz = i;
return 1;
}
return 0;
}
else {
puts( "polz(): i'm sorry, dave, but i can't do that." );
exit( 50 );
}
}
/* ========================================================================= */
void wrtList( FILE * fp, FILE * of )
{
int ptsleft, isNeeded = 0;
tNod * p;
tNod last, lz, ln;
static tNod Nod;
static Byte Buf[256];
lastpolz = -1; /* make sure it is intialized */
memset( &Nod, EOS, sizeof( Nod ) );
last.Type = Point;
last.a.z = last.a.n = last.a.f = last.a.p = -1; /* force write */
ptsleft = maxpt;
parseRec( NULL, NULL, 1 ); /* reset parseRec() state machine */
while ( ( Cfg.doInclude || ptsleft != 0 ) &&
getLine( Buf, fp, 0 ) == Buf ) {
parseRec( Buf, &Nod, 0 );
/* *** dumpRec( &Nod, NULL, 1 ); */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
if ( Cfg.doInclude == Yes ) {
if ( Nod.Type == Region ) {
printf( "\rScanning %u:%u ... ", Nod.a.z, Nod.a.n );
fflush( stdout );
}
/* this resets the include state var in case only the header of a nodelist */
/* part is desired. */
if ( isNeeded != 0 && lastpolz != -1 &&
Cfg.incNet[lastpolz].incHdr == Yes &&
( Nod.Type == Zone || Nod.Type == Region ||
Nod.Type == Host || Nod.Type == Hub ) )
isNeeded = 0;
/* the following logic decides whether to go into include-mode. isNeeded is */
/* the state variable, polz() determines whether it should be set. lower */
/* values (except 0) override higher ones in isNeeded, ensuring that the */
/* largest of any overlapping includes will be selected. */
if ( Nod.Type == Zone ) {
isNeeded = 0;
if ( polz( Zone, Nod.a ) )
isNeeded = 1;
if ( isNeeded != 1 && polz( Point, Nod.a ) ) {
wrtRec( &Nod, of, No, Cfg.termOldnet );
last = lz = Nod;
}
}
if ( isNeeded != 1 && Nod.Type == Region ) {
isNeeded = 0;
if ( polz( Region, Nod.a ) )
isNeeded = 2;
}
if ( isNeeded != 1 && isNeeded != 2 &&
Nod.Type == Host ) {
isNeeded = 0;
if ( polz( Host, Nod.a ) )
isNeeded = 3;
}
if ( isNeeded ) {
wrtRec( &Nod, of, No, Cfg.termOldnet );
last = Nod;
}
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
switch ( Nod.Type ) {
case Zone: lz = Nod; continue; /* just file it away */
case Region: printf( "\rScanning %u:%u ... ", Nod.a.z, Nod.a.n );
fflush( stdout );
case Host: ln = Nod; /* just file it away */
case Hub:
case Pvt:
case Hold:
case Down:
case Node: if ( ! needed( Nod.a ) )
continue; /* no points for that one */
if ( last.a.z != Nod.a.z ) { /* new zone? */
wrtRec( &lz, of, No, Cfg.termOldnet );
last = lz; /* set new last-written */
} /* new zone? */
if ( last.a.n != Nod.a.n ) { /* new net? */
wrtRec( &ln, of, No, Cfg.termOldnet );
last = ln; /* set new last-written */
} /* new net? */
if ( last.a.z != Nod.a.z || last.a.n != Nod.a.n ||
last.a.f != Nod.a.f )
wrtRec( &Nod, of, No, Cfg.termOldnet );
last = Nod; /* set new last-written */
break; /* fall thru to point-check */
default: continue; /* next node */
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
for ( p = pts; p != NULL; p = p->nx ) {
if ( p->a.z == Nod.a.z && p->a.n == Nod.a.n &&
p->a.f == Nod.a.f ) {
wrtRec( p, of, No, Cfg.termOldnet );
p->prcd = Yes;
ptsleft --;
} /* if pts[i].a == Nod.a */
} /* for i (all points) */
} /* while nodelist not exhausted */
fputs( "\r \r", stdout );
}
/* ========================================================================= */
int ptCmp( tNod ** p, tNod ** q )
{
tNod * pp;
tNod * qq;
pp = *p;
qq = *q;
if ( pp->a.z < qq->a.z ) return -1;
if ( pp->a.z > qq->a.z ) return 1;
if ( pp->a.n < qq->a.n ) return -1;
if ( pp->a.n > qq->a.n ) return 1;
if ( pp->a.f < qq->a.f ) return -1;
if ( pp->a.f > qq->a.f ) return 1;
if ( pp->a.p < qq->a.p ) return -1;
if ( pp->a.p > qq->a.p ) return 1;
return 0;
}
/* ========================================================================= */
void wrtClist( FILE * of )
{
tNod * p;
tAd lastw;
lastw.z = lastw.n = lastw.f = lastw.p = 0xffff; /* force boss */
for ( p = pts; p != NULL; p = p->nx ) {
if ( lastw.z != p->a.z ) {
fprintf( of, ";%sZone,%u,->%s",
Cfg.termClist, p->a.z, Cfg.termClist );
lastw.z = lastw.n = p->a.z;
lastw.f = lastw.p = 0;
}
if ( lastw.n != p->a.n ) {
fprintf( of, ";%sHost,%u,->%s",
Cfg.termClist, p->a.n, Cfg.termClist );
lastw.n = p->a.n;
lastw.f = lastw.p = 0;
}
if ( lastw.f != p->a.f ) {
fprintf( of, ",%u,->%s", p->a.f, Cfg.termClist );
lastw.f = p->a.f;
lastw.p = 0;
}
wrtRec( p, of, No, Cfg.termClist );
p->prcd = Yes;
}
}
/* ========================================================================= */
void wrt199bList( FILE * of )
{
tNod * p;
tAd lastw;
lastw.z = lastw.n = lastw.f = lastw.p = 0xffff; /* force boss */
for ( p = pts; p != NULL; p = p->nx ) {
if ( lastw.z != p->a.z || lastw.n != p->a.n ||
lastw.f != p->a.f ) {
lastw = p->a;
lastw.p = 0;
fprintf( of, ";%sBoss,%u:%u/%u%s", Cfg.termFd199b,
lastw.z, lastw.n, lastw.f, Cfg.termFd199b );
}
wrtRec( p, of, Yes, Cfg.termFd199b );
p->prcd = Yes;
}
}
/* ========================================================================= */
void readPointnet( void )
{
FILE * fp;
#if defined( BIGBUF )
char * filbuf;
#endif
static tNod Nod;
static Byte Buf[256];
fp = fopen( Cfg.iFile, O_RT );
if ( fp == NULL ) {
printf( "Can't open %s\n", Cfg.iFile );
exit( 2 );
}
#if defined( BIGBUF )
filbuf = malloc( FBUFSIZ );
if ( filbuf == NULL )
printf( "WARNING: no core for file buffer in readCfg()\n" );
else setvbuf( fp, filbuf, _IOFBF, FBUFSIZ );
#endif
inPointnet = Yes; /* notify parseRec() re. pvt points */
parseRec( NULL, NULL, 1 ); /* reset parseRec() state machine */
while ( getLine( Buf, fp, 0 ) == Buf ) {
parseRec( Buf, &Nod, 0 );
if ( Nod.Type != Node )
continue;
addNod( 1, &Nod );
maxpt ++;
}
inPointnet = No; /* reset parseRec() to kill Pvts */
fclose( fp );
#if defined( BIGBUF )
if ( filbuf != NULL )
free( filbuf );
filbuf = NULL;
#endif
}
/* ========================================================================= */
void readUserlist( void )
{
FILE * fp;
int i;
Byte * p;
#if defined( BIGBUF )
char * filbuf;
#endif
static tNod Nod;
static Byte Buf[256];
fp = fopen( Cfg.uFile, O_RT );
if ( fp == NULL ) {
printf( "Can't open %s\n", Cfg.uFile );
exit( 2 );
}
#if defined( BIGBUF )
filbuf = malloc( FBUFSIZ );
if ( filbuf == NULL )
printf( "WARNING: no core for file buffer in readCfg()\n" );
else setvbuf( fp, filbuf, _IOFBF, FBUFSIZ );
#endif
strncpy( Nod.Bbs, Cfg.sysName, sizeof( Nod.Bbs ) - 1 );
Nod.Bbs[sizeof( Nod.Bbs ) - 1] = EOS;
strncpy( Nod.City, Cfg.sysLoc, sizeof( Nod.City ) - 1 );
Nod.City[sizeof( Nod.City ) - 1] = EOS;
strncpy( Nod.Flags, POINTFLAGS, sizeof( Nod.Flags ) - 1 );
Nod.Flags[sizeof( Nod.Flags ) - 1] = EOS;
strcpy( Nod.Tel, "-Unpublished-" );
Nod.Baud = POINTBAUD;
Nod.Type = Point;
while ( getLine( Buf, fp, 0 ) == Buf ) {
parseAd( Buf + POINTADDR, &Nod.a );
if ( Nod.a.p == 0 )
continue;
if ( Nod.a.z == 0 ) Nod.a.z = Cfg.myZone;
for ( i = 0; i < Cfg.maxukill; i ++ )
if ( Cfg.killUser[i].z == Nod.a.z &&
Cfg.killUser[i].n == Nod.a.n &&
Cfg.killUser[i].f == Nod.a.f )
goto Ignore;
memset( Nod.Sysop, EOS, sizeof( Nod.Sysop ) );
p = Buf + POINTADDR;
while ( p >= Buf && *p == ' ' ) p --;
p[1] = EOS;
p = strchr( Buf, ',' );
if ( p != NULL ) {
*( p ++ ) = EOS;
skip( p );
strcpy( Nod.Sysop, p );
p = Nod.Sysop + strlen( Nod.Sysop );
if ( p > Nod.Sysop ) {
*p = ' ';
p[1] = EOS;
}
}
strcat( Nod.Sysop, Buf );
for ( p = Nod.Sysop; *p; p ++ )
if ( *p == ' ' || *p == '\t' )
*p = '_';
if ( Cfg.haveSysname == No ) /* use sysop name? */
memcpy( Nod.Bbs, Nod.Sysop, sizeof( Nod.Sysop ) );
Nod.No = Nod.a.p;
addNod( 1, &Nod );
maxpt ++;
Ignore: ;
}
fclose( fp );
#if defined( BIGBUF )
if ( filbuf != NULL )
free( filbuf );
filbuf = NULL;
#endif
}
/* ========================================================================= */
void wrtuRec( tNod * p, FILE * of )
{
Byte * q, t0[40], t1[20], t2[20];
sprintf( t1, "%u:%u", p->a.z, p->a.n );
sprintf( t2, p->a.p != 0? "%u.%u": "%u", p->a.f, p->a.p );
q = strrchr( p->Sysop, '_' );
if ( q == NULL ) strcpy( t0, p->Sysop );
else {
strcpy( t0, q + 1 );
strcat( t0, ", " );
*q = EOS;
strcat( t0, p->Sysop );
*q = '_';
}
for ( q = strchr( t0, '_' ); q != NULL; q = strchr( q, '_' ) )
*q = ' ';
fprintf( of, "%-40s %14.14s/%-14.14s%s", t0, t1, t2, Cfg.termUser );
/* *** dumpRec( p, NULL, 1 ); */
}
/* ========================================================================= */
void wrtuList( FILE * fp, FILE * of )
{
int ptsleft, isNeeded = 0;
tNod * p;
tNod last, lz, ln;
static tNod Nod;
static Byte Buf[256];
lastpolz = -1; /* make sure it is intialized */
memset( &Nod, EOS, sizeof( Nod ) );
last.Type = Point;
last.a.z = last.a.n = last.a.f = last.a.p = -1; /* force write */
ptsleft = maxpt;
parseRec( NULL, NULL, 1 ); /* reset parseRec() state machine */
while ( ( Cfg.uoInclude || ptsleft != 0 ) &&
getLine( Buf, fp, 0 ) == Buf ) {
parseRec( Buf, &Nod, 0 );
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
if ( Cfg.uoInclude == Yes ) {
if ( Nod.Type == Region ) {
printf( "\rScanning %u:%u ... ", Nod.a.z, Nod.a.n );
fflush( stdout );
}
/* this resets the include state var in case only the header of a nodelist */
/* part is desired. */
if ( isNeeded != 0 && lastpolz != -1 &&
Cfg.incNet[lastpolz].incHdr == Yes &&
( Nod.Type == Zone || Nod.Type == Region ||
Nod.Type == Host || Nod.Type == Hub ) )
isNeeded = 0;
/* the following logic decides whether to go into include-mode. isNeeded is */
/* the state variable, polz() determines whether it should be set. lower */
/* values (except 0) override higher ones in isNeeded, ensuring that the */
/* largest of any overlapping includes will be selected. */
if ( Nod.Type == Zone ) {
isNeeded = 0;
if ( polz( Zone, Nod.a ) )
isNeeded = 1;
if ( isNeeded != 1 && polz( Point, Nod.a ) ) {
wrtuRec( &Nod, of );
last = lz = Nod;
}
}
if ( isNeeded != 1 && Nod.Type == Region ) {
isNeeded = 0;
if ( polz( Region, Nod.a ) )
isNeeded = 2;
}
if ( isNeeded != 1 && isNeeded != 2 &&
Nod.Type == Host ) {
isNeeded = 0;
if ( polz( Host, Nod.a ) )
isNeeded = 3;
}
if ( isNeeded ) {
wrtuRec( &Nod, of );
last = Nod;
}
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
switch ( Nod.Type ) {
case Zone: lz = Nod; continue; /* just file it away */
case Region: printf( "\rScanning %u:%u ... ", Nod.a.z, Nod.a.n );
fflush( stdout );
case Host: ln = Nod; /* just file it away */
case Hub:
case Node: if ( ! needed( Nod.a ) )
continue; /* no points for that one */
if ( last.a.z != Nod.a.z ) { /* new zone? */
wrtuRec( &lz, of );
last = lz; /* set new last-written */
} /* new zone? */
if ( last.a.n != Nod.a.n ) { /* new net? */
wrtuRec( &ln, of );
last = ln; /* set new last-written */
} /* new net? */
if ( last.a.z != Nod.a.z || last.a.n != Nod.a.n ||
last.a.f != Nod.a.f )
wrtuRec( &Nod, of );
last = Nod; /* set new last-written */
break; /* fall thru to point-check */
default: continue; /* next node */
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
for ( p = pts; p != NULL; p = p->nx ) {
if ( p->a.z == Nod.a.z && p->a.n == Nod.a.n &&
p->a.f == Nod.a.f ) {
wrtuRec( p, of );
p->prcd = Yes;
ptsleft --;
} /* if pts[i].a == Nod.a */
} /* for i (all points) */
} /* while nodelist not exhausted */
fputs( "\r \r", stdout );
}
/* ========================================================================= */
void copyProlog( FILE * of, Byte * name, Byte * term )
{
FILE * fp;
#if defined( BIGBUF )
char * filbuf;
#endif
Byte c;
fp = fopen( name, O_RT );
if ( fp != NULL ) {
#if defined( BIGBUF )
filbuf = malloc( FBUFSIZ );
if ( filbuf == NULL )
printf( "WARNING: no core for file buffer in readCfg()\n" );
else setvbuf( fp, filbuf, _IOFBF, FBUFSIZ );
#endif
c = (Byte) getc( fp );
while ( ( ! ferror( fp ) ) && ( ! feof( fp ) ) ) {
if ( c == '\n' )
fputs( term, of );
else putc( c, of );
c = (Byte) getc( fp );
}
fclose( fp );
#if defined( BIGBUF )
if ( filbuf != NULL )
free( filbuf );
filbuf = NULL;
#endif
}
}
/* ========================================================================= */
void readInfd199b( void )
{
FILE * fp;
#if defined( BIGBUF )
char * filbuf;
#endif
static tNod Nod;
static Byte Buf[256];
fp = fopen( Cfg.bFile, O_RT );
if ( fp == NULL ) {
printf( "Can't open %s\n", Cfg.bFile );
exit( 2 );
}
#if defined( BIGBUF )
filbuf = malloc( FBUFSIZ );
if ( filbuf == NULL )
printf( "WARNING: no core for file buffer in readCfg()\n" );
else setvbuf( fp, filbuf, _IOFBF, FBUFSIZ );
#endif
inFd199b = Yes; /* notify parseRec() re. Fd199b */
parseRec( NULL, NULL, 1 ); /* reset parseRec() state machine */
while ( getLine( Buf, fp, 0 ) == Buf ) {
parseRec( Buf, &Nod, 0 );
if ( Nod.Type != Point )
continue;
addNod( 1, &Nod );
maxpt ++;
}
inFd199b = No; /* reset parseRec() */
fclose( fp );
#if defined( BIGBUF )
if ( filbuf != NULL )
free( filbuf );
filbuf = NULL;
#endif
}
/* ========================================================================= */
int main( int argc, Byte * argv[] )
{
FILE * fp, * of;
#if defined( BIGBUF )
char * filbuf1, * filbuf2;
#endif
tNod * p;
long nBytes;
static tNod Nod;
static Byte cfgName[80];
#if ! defined( AMIGA )
union REGS regs;
#endif /* AMIGA */
/* ------------------------------------------------------------------------- */
printf( "%s: Militantly Public Domain.\n", VER );
strcpy( cfgName, CFGNAME );
if ( argc > 1 ) strcpy( cfgName, argv[1] );
readCfg( cfgName ); /* get config info */
printf( "FYI: config record is %u bytes long, one node entry uses %u bytes.\n",
sizeof( tCfg ), sizeof( tNod ) );
#if defined( AMIGA )
nBytes = (long) AvailMem( MEMF_LARGEST );
#else /* AMIGA */
regs.x.bx = 0xffff; regs.h.ah = 0x48;
intdos( ®s, ®s );
if ( ! regs.x.cflag ) {
puts( "damn. a mem alloc which should have failed is OK." );
puts( "i guess i'll just give up ... please report this error." );
return 10;
}
nBytes = ( (long) regs.x.bx ) * 16L;
#endif /* AMIGA */
printf( " you have some %lu bytes available for points (abt. %luK). this\n", nBytes, nBytes / 1024L );
printf( " setup will handle about %lu point entries and accepts %u valid\n", nBytes / (long) sizeof( tNod ), MAXCMD );
printf( " config commands. %u \042map\042 statements were found, and memory\n", Cfg.maxmap );
printf( " for %u was allocated.\n", MAXMAP );
fflush( stdout );
/* ------------------------------------------------------------------------- */
pts = NULL;
/* ------------------------------------------------------------------------- */
memset( &Nod, EOS, sizeof( Nod ) );
if ( Cfg.havePointnet == Yes )
readPointnet();
killNets();
mapNets();
if ( Cfg.haveInfd199b == Yes )
readInfd199b();
if ( Cfg.haveUserlist == Yes )
readUserlist();
for ( p = pts; p != NULL; p = p->nx )
p->a.z = Cfg.myZone;
if ( maxpt == 0 ) {
puts( "\nNothing left to process -- aborted." );
exit( 0 );
}
if ( maxpt > 1 ) {
tNod ** pp;
tNod ** i;
pp = malloc( ( maxpt + 1 ) * sizeof( tNod * ) );
if ( pp == NULL ) {
puts( "\nshit, everything looked so good and then i didn't have enough" );
puts( "memory for the goddam sort ... what a mess!" );
exit( 99 );
}
for ( p = pts, i = pp; p != NULL; p = p->nx, i ++ )
*i = p;
qsort( (char *) &pp[0], maxpt, sizeof( tNod * ), ptCmp );
pts = pp[0];
pp[maxpt] = NULL;
for ( i = &pp[0]; i < &pp[maxpt]; i ++ )
( *i )->nx = *( i + 1 );
free( pp );
}
removeNets();
printf( "the actual number of points being processed is %u.\n", maxpt );
/* ------------------------------------------------------------------------- */
if ( Cfg.Oldnet == Yes ) {
printf( "Generating FD 1.99 private list %s\n", Cfg.oFile );
of = fopen( Cfg.oFile, O_WB );
if ( of == NULL ) {
printf( "Yuck: can't create %s\n", Cfg.oFile );
exit( 2 );
}
#if defined( BIGBUF )
filbuf2 = malloc( FBUFSIZ );
if ( filbuf2 == NULL )
printf( "WARNING: no core for file buffer in readCfg()\n" );
else setvbuf( of, filbuf2, _IOFBF, FBUFSIZ );
#endif
fprintf( of, HDR, "oldnet", VER, Cfg.termOldnet );
if ( Cfg.haveProlog == Yes )
copyProlog( of, Cfg.pFile, Cfg.termOldnet );
fp = fopen( Cfg.nFile, O_RT );
if ( fp == NULL ) {
printf( "Yuck: can't open %s\n", Cfg.nFile );
exit( 2 );
}
#if defined( BIGBUF )
filbuf1 = malloc( FBUFSIZ );
if ( filbuf1 == NULL )
printf( "WARNING: no core for file buffer in readCfg()\n" );
else setvbuf( fp, filbuf1, _IOFBF, FBUFSIZ );
#endif
wrtList( fp, of );
fclose( fp );
#if defined( BIGBUF )
if ( filbuf1 != NULL )
free( filbuf1 );
filbuf1 = NULL;
#endif
if ( Cfg.haveEpilog == Yes )
copyProlog( of, Cfg.eFile, Cfg.termOldnet );
fclose( of );
#if defined( BIGBUF )
if ( filbuf2 != NULL )
free( filbuf2 );
filbuf2 = NULL;
#endif
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
if ( Cfg.haveUserout == Yes ) {
printf( "Generating FIDOUSER.LST-style list %s\n", Cfg.tFile );
of = fopen( Cfg.tFile, O_WB );
if ( of == NULL ) {
printf( "Yuck: can't create %s\n", Cfg.tFile );
exit( 2 );
}
#if defined( BIGBUF )
filbuf2 = malloc( FBUFSIZ );
if ( filbuf2 == NULL )
printf( "WARNING: no core for file buffer in readCfg()\n" );
else setvbuf( of, filbuf2, _IOFBF, FBUFSIZ );
#endif
fp = fopen( Cfg.nFile, O_RT );
if ( fp == NULL ) {
printf( "Yuck: can't open %s\n", Cfg.nFile );
exit( 2 );
}
#if defined( BIGBUF )
filbuf1 = malloc( FBUFSIZ );
if ( filbuf1 == NULL )
printf( "WARNING: no core for file buffer in readCfg()\n" );
else setvbuf( fp, filbuf1, _IOFBF, FBUFSIZ );
#endif
wrtuList( fp, of );
fclose( of );
#if defined( BIGBUF )
if ( filbuf2 != NULL )
free( filbuf2 );
filbuf2 = NULL;
#endif
fclose( fp );
#if defined( BIGBUF )
if ( filbuf1 != NULL )
free( filbuf1 );
filbuf1 = NULL;
#endif
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
if ( Cfg.Fd199b == Yes ) {
printf( "Generating FD 1.99c point list %s\n", Cfg.fFile );
of = fopen( Cfg.fFile, O_WB );
if ( of == NULL ) {
printf( "Yuck: can't create %s\n", Cfg.fFile );
exit( 2 );
}
#if defined( BIGBUF )
filbuf2 = malloc( FBUFSIZ );
if ( filbuf2 == NULL )
printf( "WARNING: no core for file buffer in readCfg()\n" );
else setvbuf( of, filbuf2, _IOFBF, FBUFSIZ );
#endif
fprintf( of, HDR, "fd199b", VER, Cfg.termFd199b );
if ( Cfg.haveProlog == Yes )
copyProlog( of, Cfg.pFile, Cfg.termFd199b );
wrt199bList( of );
if ( Cfg.haveEpilog == Yes )
copyProlog( of, Cfg.eFile, Cfg.termFd199b );
fclose( of );
#if defined( BIGBUF )
if ( filbuf2 != NULL )
free( filbuf2 );
filbuf2 = NULL;
#endif
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
if ( Cfg.Clist == Yes ) {
printf( "Generating CLIST point list %s\n", Cfg.cFile );
of = fopen( Cfg.cFile, O_WB );
if ( of == NULL ) {
printf( "Yuck: can't create %s\n", Cfg.cFile );
exit( 2 );
}
#if defined( BIGBUF )
filbuf2 = malloc( FBUFSIZ );
if ( filbuf2 == NULL )
printf( "WARNING: no core for file buffer in readCfg()\n" );
else setvbuf( of, filbuf2, _IOFBF, FBUFSIZ );
#endif
fprintf( of, HDR, "clist", VER, Cfg.termClist );
if ( Cfg.haveProlog == Yes )
copyProlog( of, Cfg.pFile, Cfg.termClist );
wrtClist( of );
if ( Cfg.haveEpilog == Yes )
copyProlog( of, Cfg.eFile, Cfg.termClist );
fclose( of );
#if defined( BIGBUF )
if ( filbuf2 != NULL )
free( filbuf2 );
filbuf2 = NULL;
#endif
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
for ( p = pts; p != NULL; p = p->nx )
if ( p->prcd == Yes )
p->a.z = p->a.n = p->a.f = p->a.p = 0;
removeNets(); /* clear written points */
if ( maxpt > 0 ) {
puts( "The following systems were not written due to the lack of a bossnode" );
puts( "entry in the specified nodelist:" );
dumpList();
}
else puts( "Input exhausted -- finished." );
/* ------------------------------------------------------------------------- */
unlink( Cfg.lFile );
if ( Cfg.haveUserout == Yes ) {
static Byte t[128], *p;
static Byte * args[MAXARGS];
int i;
while ( ( p = strstr( Cfg.Sort, "{in}" ) ) != NULL ) {
memcpy( t, Cfg.Sort, p - Cfg.Sort );
t[p - Cfg.Sort] = EOS;
strcat( t, Cfg.tFile );
strcat( t, p + 4 ); /* len of "{in}" */
strcpy( Cfg.Sort, t ); /* for next pass thru loop */
}
while ( ( p = strstr( Cfg.Sort, "{out}" ) ) != NULL ) {
memcpy( t, Cfg.Sort, p - Cfg.Sort );
t[p - Cfg.Sort] = EOS;
strcat( t, Cfg.lFile );
strcat( t, p + 5 ); /* len of "{out}" */
strcpy( Cfg.Sort, t ); /* for next pass thru loop */
}
printf( "Executing: %s\n", Cfg.Sort );
#if defined( AMIGA )
i = ! Execute( Cfg.Sort, NULL, NULL );
/* {
struct ProcID pid;
if ( ( i = forkv( args[0], args, NULL, &pid ) ) != -1 )
i = wait( &pid );
}
*/
#else /* AMIGA */
p = strtok( Cfg.Sort, " " );
i = 0;
while ( p != NULL ) {
if ( i >= MAXARGS - 1 ) {
printf( "sorry, but your sort command has more than %u tokens.\n", MAXARGS );
unlink( Cfg.tFile );
exit( 2 );
}
args[i ++] = p;
p = strtok( NULL, " " );
}
args[i] = NULL;
i = spawnvp( P_WAIT, args[0], args );
#endif /* AMIGA */
if ( i == -1 ) {
perror( "main/execsort" );
unlink( Cfg.tFile );
exit( 2 );
}
else if ( i )
printf( "Warning: %s returned %u\n", args[0], i );
fp = fopen( Cfg.lFile, O_RT );
if ( fp == NULL ) {
printf( "error: sort did not generate %s\n", Cfg.lFile );
exit( 2 );
}
fclose( fp );
unlink( Cfg.tFile );
}
/* ------------------------------------------------------------------------- */
if ( Cfg.havePointnet == Yes && Cfg.killInput == Yes )
if ( unlink( Cfg.iFile ) != 0 ) {
printf( "main: can't unlink %s\n", Cfg.iFile );
return 1;
}
if ( Cfg.haveUserlist == Yes && Cfg.killUserlist == Yes )
if ( unlink( Cfg.uFile ) != 0 ) {
printf( "main: can't unlink %s\n", Cfg.uFile );
return 1;
}
if ( Cfg.haveInfd199b == Yes && Cfg.killInfd199b == Yes )
if ( unlink( Cfg.bFile ) != 0 ) {
printf( "main: can't unlink %s\n", Cfg.bFile );
return 1;
}
return 0;
}
/* ========================================================================= */